<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Rag Hu
 * Created Time: 2019/8/12 15:34
 * Modified Time: 2019/8/12 15:34
 * Version: 2.0
 */

namespace App\Modules\Inventory\Repositories;


use App\Models\GoodsCart;
use Flower\Core\Repository\Eloquent\BaseRepository;

class GoodsCartRepository extends BaseRepository
{
    public function model()
    {
        return GoodsCart::class;
    }

    /**
     * 添加购物车
     * @param $user_id
     * @param $store_id
     * @param $goods_id
     * @param $num
     * @return mixed
     */
    public function createGoodsCard($user_id,$store_id,$goods_id,$num)
    {
        $data = [
            'user_id'=>$user_id,
            'store_id'=>$store_id,
            'goods_id'=>$goods_id,
            'num'=>$num
        ];
        return $this->create($data);
    }

    /**
     * 存在则删除购物车
     * @param $goods_card_id
     */
    public function deleteExistById($goods_card_id)
    {
        if($this->find($goods_card_id)){
            $this->delete($goods_card_id);
        }
    }


}